<template>
  <page-header-wrapper>
    <a-card title="佣金钱包" style="margin-bottom:20px">
      <div class="top-balance-wrapper">
        <div class="top-balance">
          <span>钱包余额(元)</span>
          <span class="balance-num">{{ summaryObj.cashAmount }}</span>
        </div>
        <div class="top-balance">
          <span>在途利润(元)</span>
          <span class="balance-num-block">{{ summaryObj.agentFeeAmount }}</span>
        </div>
      </div>
    </a-card>
    <a-card>
      <div class="table-page-search-wrapper">
        <a-form layout="inline" class="table-head-ground">
          <div class="table-layer">
            <a-form-item label="" class="table-head-layout">
              <a-select v-model="searchData.state" placeholder="申请状态" default-value="">
                <a-select-option value="">全部</a-select-option>
                <a-select-option value="0">失败</a-select-option>
                <a-select-option value="1">审核中</a-select-option>
                <a-select-option value="2">提现成功</a-select-option>
              </a-select>
            </a-form-item>
            <span class="table-page-search-submitButtons" style="flex-grow: 0; flex-shrink: 0;">
              <a-button type="primary" icon="search" @click="queryFunc" :loading="btnLoading">查询</a-button>
              <a-button style="margin-left: 8px" icon="reload" @click="() => this.searchData = {}">重置</a-button>
            </span>
          </div>
        </a-form>
        <div>
          <a-button v-if="$access('ENT_AGENT_ACCOUNT_HISHOST_ADD')" type="primary" icon="plus" @click="addFunc" class="mg-b-30">发起提现</a-button>
        </div>
      </div>

      <!-- 列表渲染 -->
      <JeepayTable
        @btnLoadClose="btnLoading=false"
        ref="infoTable"
        :initData="true"
        :reqTableDataFunc="reqTableDataFunc"
        :tableColumns="tableColumns"
        :searchData="searchData"
        rowKey="mchNo"
      >
        <template slot="mchNameSlot" slot-scope="{record}">
          <b>{{ record.agentName }}</b>
        </template> <!-- 自定义插槽 -->
        <template slot="stateSlot" slot-scope="{record}">
          <a-badge v-if="record.state === 0" status='error' text='失败' />
          <a-badge v-else-if="record.state === 1" status='processing' text='审核中' />
          <a-badge v-else-if="record.state === 2" status='success' text='提现成功' />
        </template>
      </JeepayTable>
    </a-card>
    <!-- 新增页面组件  -->
    <InfoAddOrEdit ref="infoAddOrEdit" :callbackFunc="searchFunc"/>
  </page-header-wrapper>
</template>
<script>
/* eslint-disable camelcase */
import JeepayTable from '@/components/JeepayTable/JeepayTable'
import JeepayTextUp from '@/components/JeepayTextUp/JeepayTextUp' // 文字上移组件
import JeepayTableColumns from '@/components/JeepayTable/JeepayTableColumns'
import { API_URL_AGENT_ACCOUNT, API_URL_AGENT_ACCOUNT_SUMMARY, req } from '@/api/manage'
import InfoAddOrEdit from './AddOrEdit'

// eslint-disable-next-line no-unused-vars
const tableColumns = [
  { key: 'createdAt', fixed: 'left', title: '申请时间', dataIndex: 'createdAt' },
  { key: 'amount', title: '提取金额', dataIndex: 'amount' },
  { key: 'state', title: '申请状态', width: '130px', scopedSlots: { customRender: 'stateSlot' } }
]

export default {
  name: 'MchListPage',
  components: { JeepayTable, JeepayTableColumns, InfoAddOrEdit, JeepayTextUp },
  data () {
    return {
      btnLoading: false,
      tableColumns: tableColumns,
      searchData: {},
      value: "''",
      summaryObj: {
        agentFeeAmount: 0,
        cashAmount: 0
      }
    }
  },
  mounted () {
    this.reqSummaryDataFunc(this)
  },
  methods: {
    queryFunc () {
      this.btnLoading = true
      this.$refs.infoTable.refTable(true)
    },
    // 请求佣金接口数据
    reqSummaryDataFunc: async (params) => {
      const data = await req.list(API_URL_AGENT_ACCOUNT_SUMMARY)
      params.summaryObj = data
    },
    // 请求table接口数据
    reqTableDataFunc: (params) => {
      return req.list(API_URL_AGENT_ACCOUNT, params)
    },
    searchFunc: function () { // 点击【查询】按钮点击事件
      this.$refs.infoTable.refTable(true)
    },
    addFunc: function () { // 业务通用【新增】 函数
      this.$refs.infoAddOrEdit.show()
    }
  }
}
</script>
